home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / sphere.scm < prev    next >
Encoding:
Text File  |  2005-06-30  |  2.7 KB  |  82 lines

  1. ;  Create a 3D sphere with optional shadow
  2. ;  The sphere's principle color will be the foreground
  3. ;  Parameters:
  4. ;   bg-color: background color
  5. ;   sphere-color: color of sphere
  6. ;   radius: radius of the sphere in pixels
  7. ;   light:  angle of light source in degrees
  8. ;   shadow: whather to create a shadow as well
  9.  
  10. (define (script-fu-sphere radius
  11.               light
  12.               shadow
  13.               bg-color
  14.               sphere-color)
  15.   (let* ((width (* radius 3.75))
  16.      (height (* radius 2.5))
  17.      (img (car (gimp-image-new width height RGB)))
  18.      (drawable (car (gimp-layer-new img width height RGB-IMAGE
  19.                     "Sphere Layer" 100 NORMAL-MODE)))
  20.      (radians (/ (* light *pi*) 180))
  21.      (cx (/ width 2))
  22.      (cy (/ height 2))
  23.      (light-x (+ cx (* radius (* 0.6 (cos radians)))))
  24.      (light-y (- cy (* radius (* 0.6 (sin radians)))))
  25.      (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
  26.      (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
  27.      (offset (* radius 0.1)))
  28.  
  29.     (gimp-context-push)
  30.  
  31.     (gimp-image-undo-disable img)
  32.     (gimp-image-add-layer img drawable 0)
  33.     (gimp-context-set-foreground sphere-color)
  34.     (gimp-context-set-background bg-color)
  35.     (gimp-edit-fill drawable BACKGROUND-FILL)
  36.     (gimp-context-set-background '(20 20 20))
  37.     (if (and
  38.      (or (and (>= light 45) (<= light 75))
  39.          (and (<= light 135) (>= light 105)))
  40.      (= shadow TRUE))
  41.     (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
  42.           (shadow-h (* radius 0.5))
  43.           (shadow-x cx)
  44.           (shadow-y (+ cy (* radius 0.65))))
  45.       (if (< shadow-w 0)
  46.           (prog1 (set! shadow-x (+ cx shadow-w))
  47.              (set! shadow-w (- shadow-w))))
  48.  
  49.       (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h
  50.                    CHANNEL-OP-REPLACE TRUE TRUE 7.5)
  51.       (gimp-edit-bucket-fill drawable BG-BUCKET-FILL MULTIPLY-MODE 100 0 FALSE 0 0)))
  52.  
  53.     (gimp-ellipse-select img (- cx radius) (- cy radius)
  54.              (* 2 radius) (* 2 radius) CHANNEL-OP-REPLACE TRUE FALSE 0)
  55.  
  56.     (gimp-edit-blend drawable FG-BG-RGB-MODE NORMAL-MODE
  57.              GRADIENT-RADIAL 100 offset REPEAT-NONE FALSE
  58.              FALSE 0 0 TRUE
  59.              light-x light-y light-end-x light-end-y)
  60.  
  61.     (gimp-selection-none img)
  62.     (gimp-image-undo-enable img)
  63.     (gimp-display-new img)
  64.  
  65.     (gimp-context-pop)))
  66.  
  67. (script-fu-register "script-fu-sphere"
  68.             _"_Sphere..."
  69.             "Simple sphere with a drop shadow"
  70.             "Spencer Kimball"
  71.             "Spencer Kimball"
  72.             "1996"
  73.             ""
  74.             SF-ADJUSTMENT _"Radius (pixels)"    '(100 5 500 1 10 0 1)
  75.             SF-ADJUSTMENT _"Lighting (degrees)" '(45 0 360 1 10 0 0)
  76.             SF-TOGGLE     _"Shadow"             TRUE
  77.             SF-COLOR      _"Background color"   '(255 255 255)
  78.             SF-COLOR      _"Sphere color"       '(255 0 0))
  79.  
  80. (script-fu-menu-register "script-fu-sphere"
  81.              _"<Toolbox>/Xtns/Script-Fu/Misc")
  82.